package pri.black.dogview.domain;

import lombok.Data;

import java.io.Serializable;

public class R implements Serializable {
    private int code;
    private String msg;
    private Object data;

    private R() {
        this.code = 200;
        this.msg = "success";
    }

    public static R ok(){
        return new R();
    }

    public static R ok(boolean da) {
        if (da) {
            R ok = ok();
            return ok;
        }else {
            R ok = fail();
            return ok;
        }
    }

    public static R ok(Object da) {
        R ok = ok();
        ok.data = da;
        return ok;
    }

    public static R fail(String msg) {
        R fail = fail();
        fail.setMsg(msg);
        return fail;
    }

    public static R fail(){
        R r = new R();
        r.code = 500;
        r.msg = "fail";
        return r;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
